package com.qqtech.qquan.circle.service;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.qqtech.core.frame.dao.BaseDao;
import com.qqtech.core.frame.service.BaseServiceImpl;
import com.qqtech.qquan.circle.dao.CircleMemberLogDao;
import com.qqtech.qquan.circle.enums.CircleMemberLogStatusDictEnum;
import com.qqtech.qquan.circle.model.CircleMemberLog;

@Service
public class CircleMemberLogServiceImpl extends BaseServiceImpl<CircleMemberLog>
		implements CircleMemberLogService {
	public static final Logger log = LoggerFactory.getLogger(CircleMemberLogServiceImpl.class);
	
	@Resource
	private CircleMemberLogDao circleMemberLogDao;

	@Override
	protected BaseDao<CircleMemberLog> getBaseDao() {
		return circleMemberLogDao;
	}
	
	@Override
	public boolean isFirstJoinCircle(Integer userId, Integer circleId) {
		CircleMemberLog memberLog = new CircleMemberLog();
		memberLog.setCircleId(circleId);
		memberLog.setMemberId(userId);
		return circleMemberLogDao.queryCount(memberLog) == 0;
	}
	
	@Override
	public int logJoinCircle(Integer userId, Integer circleId) {
		CircleMemberLog memberLog = new CircleMemberLog();
		memberLog.setCircleId(circleId);
		memberLog.setMemberId(userId);
		memberLog.setStatus(CircleMemberLogStatusDictEnum.NORMAL.getCode());
		return circleMemberLogDao.insert(memberLog);
	}

	@Override
	public int logKillOutCircle(Integer userId, Integer circleId) {
		CircleMemberLog memberLog = new CircleMemberLog();
		memberLog.setCircleId(circleId);
		memberLog.setMemberId(userId);
		memberLog.setStatus(CircleMemberLogStatusDictEnum.BEKILLOUT.getCode());
		return circleMemberLogDao.insert(memberLog);
	}

	@Override
	public int logQuitOutCircle(Integer userId, Integer circleId) {
		CircleMemberLog memberLog = new CircleMemberLog();
		memberLog.setCircleId(circleId);
		memberLog.setMemberId(userId);
		memberLog.setStatus(CircleMemberLogStatusDictEnum.QUITOUT.getCode());
		return circleMemberLogDao.insert(memberLog);
	}
	
}